package com.sps.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sps.common.annotation.Log;
import com.sps.common.core.controller.BaseController;
import com.sps.common.core.domain.AjaxResult;
import com.sps.common.enums.BusinessType;
import com.sps.business.domain.CcRukuInfo;
import com.sps.business.service.ICcRukuInfoService;
import com.sps.common.utils.poi.ExcelUtil;
import com.sps.common.core.page.TableDataInfo;

/**
 * 入库任务Controller
 * 
 * @author 王超
 * @date 2025-03-04
 */
@RestController
@RequestMapping("/business/ccRukuInfo")
public class CcRukuInfoController extends BaseController
{
    @Autowired
    private ICcRukuInfoService ccRukuInfoService;

    /**
     * 查询入库任务列表
     */
    @PreAuthorize("@ss.hasPermi('business:ccRukuInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(CcRukuInfo ccRukuInfo)
    {
        startPage();
        List<CcRukuInfo> list = ccRukuInfoService.selectCcRukuInfoList(ccRukuInfo);
        return getDataTable(list);
    }


    @GetMapping("/listGroup")
    public TableDataInfo listGroup(CcRukuInfo ccRukuInfo)
    {
        startPage();
        List<CcRukuInfo> list = ccRukuInfoService.selectCcRukuInfoListGroup(ccRukuInfo);
        return getDataTable(list);
    }



    /**
     * 导出入库任务列表
     */
    @PreAuthorize("@ss.hasPermi('business:ccRukuInfo:export')")
    @Log(title = "入库任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CcRukuInfo ccRukuInfo)
    {
        List<CcRukuInfo> list = ccRukuInfoService.selectCcRukuInfoList(ccRukuInfo);
        ExcelUtil<CcRukuInfo> util = new ExcelUtil<CcRukuInfo>(CcRukuInfo.class);
        util.exportExcel(response, list, "入库任务数据");
    }

    /**
     * 获取入库任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:ccRukuInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ccRukuInfoService.selectCcRukuInfoById(id));
    }

    /*
     *手机端获取补货任务详情（手机端扫码获取数据使用）getCcRukuInfoByCodeAndLable
     */
    @GetMapping(value = "getCcRukuInfoByCodeAndLable/{planCode}/{lableCode}")
    public AjaxResult getCcRukuInfoByCodeAndLable(@PathVariable("planCode") String planCode,@PathVariable("lableCode") String lableCode)
    {
        return success(ccRukuInfoService.selectCcRukuInfoByCodeAndLable(planCode,lableCode));
    }


    /**
     * 新增入库任务
     */
    @PreAuthorize("@ss.hasPermi('business:ccRukuInfo:add')")
    @Log(title = "入库任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CcRukuInfo ccRukuInfo)
    {
        return toAjax(ccRukuInfoService.insertCcRukuInfo(ccRukuInfo));
    }


    /**
     * 新增入库任务（手机端用）
     */
    @Log(title = "入库任务", businessType = BusinessType.INSERT)
    @PostMapping("/addList")
    public AjaxResult addList(@RequestBody  List<CcRukuInfo>  ccRukuInfoList)
    {
        return toAjax(ccRukuInfoService.insertCcRukuInfoList(ccRukuInfoList));
    }



    /**
     * 修改入库任务
     */
    @PreAuthorize("@ss.hasPermi('business:ccRukuInfo:edit')")
    @Log(title = "修改入库任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CcRukuInfo ccRukuInfo)
    {
        return toAjax(ccRukuInfoService.updateCcRukuInfo(ccRukuInfo));
    }


    @Log(title = "修改打印状态和次数", businessType = BusinessType.UPDATE)
    @PutMapping("/editRukuStatus")
    public AjaxResult editRukuStatus(@RequestBody CcRukuInfo ccRukuInfo)
    {
        return toAjax(ccRukuInfoService.updateCcRukuInfoRuKuStatus(ccRukuInfo));
    }


    /*
     * 移动端扫码入库 updateCcRukuInfoByPlanCode
     */
    @Log(title = "手机扫码入库确认", businessType = BusinessType.UPDATE)
    @PutMapping("/updateCcRukuInfoByPlanCode")
    public AjaxResult editByPlanCode(@RequestBody CcRukuInfo ccRukuInfo)
    {
        return toAjax(ccRukuInfoService.updateCcRukuInfoByPlanCode(ccRukuInfo));
    }

    /**
     * 删除入库任务
     */
    @PreAuthorize("@ss.hasPermi('business:ccRukuInfo:remove')")
    @Log(title = "入库任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ccRukuInfoService.deleteCcRukuInfoByIds(ids));
    }
}
